package com.ruoyi.websocket;

/**
 * @projectName: ruoyi
 * @package: com.ruoyi.websocket
 * @className: apiRequest
 * @author: 徐源长
 * @description:
 */


import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionChoice;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionRequest;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.volcengine.ark.runtime.service.ArkService;

import java.util.List;


public class apiRequest {
    static String apiKey = "";
    static ArkService service = ArkService.builder().apiKey(apiKey).baseUrl("https://ark.cn-beijing.volces.com/api/v3/").build();

    public static String request(List<ChatMessage> messages) {

        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
                .model("")//这个写你的ep-开头的id
                .messages(messages)
                .build();

        ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
        String reply = choice.getMessage().stringContent();
//        System.out.println(reply);
        // shutdown service
        service.shutdownExecutor();
        System.out.println("服务器发送消息" + reply);
        return reply;
    }
}
